local desc_lzhou = [[
  # 龙舟激浪 模式简介

  可以自选开启需要的将池

  硬核模式，人越多越简单

  适配1~3真人玩家游玩
  
  请确保玩家与房间总人数为:1-4,2-7,3-10之一

  ——————————————————————————

  玩法介绍：

  选武将选将灵打BOSS，总共4 + 1关

  每轮一个天气刷新

  每回合通过摸牌，回复，砸伤，拆顺BOSS手牌可以增加龙舟进度

  每项进度每回合限加20米

  龙舟进度于最终关会转化为加伤增益及双方体力上限增益
  


]]

-- FIXME: Disable same convert by param or extra data
local LangAI = require "packages/tshu/AI/LangAI"
local T = require "packages/tshu/record/Theorem"
local U = require "packages/utility/utility"

local lzhou_getLogic = function()
  local lzhou_logic = GameLogic:subclass("lzhou_logic")
  ---虚拟偶像
  local ox = {"tshuox__xiaosha","tshuox__xiaojiu","tshuox__xiaotao","tshuox__xiaole","tshuox__xiaoshan"}
  --诸神
  local godboss = {"tshugod__kuafu","tshugod__shaohao","tshugod__xuannv","tshugod__hanba","tshugod__yanluowang"}
    --年夕兽
  local nx = {"tshunx__nwei","tshunx__nqun","tshunx__nshu","tshunx__nwu","tshunx__xwu","tshunx__xwei","tshunx__xqun","tshunx__xshu","tshunx__pucong"}
  --生肖
  local sx = {"tshusx__shu","tshusx__niu","tshusx__hu","tshusx__tu","tshusx__long","tshusx__she","tshusx__ma","tshusx__yang","tshusx__hou","tshusx__ji","tshusx__gou","tshusx__zhu"}
  --黑名单
  local black = {"mouxusheng","tshujl__zhouyi","tshujl__zhugeguo","tshujl__lingjv","tshujl__zhouyu","tshujl__caoying","tshujl__guansuo","tshujl__nianshou","tshujl__zhaoxiang","tshujl__xiaosha","tshujl__caochun","tshulz__zuogu","tshulz__yougu","tshujl__guanyu","tshujl__zhaoyun","lingju","joyo__nvwa","joy__godzhangfei","godzhangfei"}
  --神
  local god = {"godjiaxu","godxuchu","goddengai","joy__godzhouyu","joy__godzuoci", "joy__godliubei","joy__goddiaochan","joy__godzhenji","joy__goddaxiaoqiao","joy__godhuatuo","joy__goddianwei","joy__godzhaoyun", "joy__godganning","joy__godguanyu","joy__godcaocao", "joy__godtaishici","joy__godlvbu","joy__godlvmeng","joy__godzhangliao","joy__godsunquan","joy__godmachao","joy__godzhangjiao","joy__godjiangwei","joy__godxunyu","joy__godsunce","joy__godguojia","joy__godluxun","joy__godsimayi","joy__godzhugeliang"}
  --保留印记
  local nmark = {"tshu__tianshu","tshu__buff1","tshu__buff2","tshu__buff3","tshu__buff4","tshu__win","@ganlu","@lzhou__zd"}
  --白名单武将包
  local white = {"joy","jsrg","mobile","mini","mougong","offline","ol","shzl","sp","standard","standard_ex","tenyear","yj","Tdiy"}

  --龙舟BOSS
  local lzboss = {"tshugod__caoe","tshugod__taoshen","tshugod__hebo","tshugod__yuershen"}

  local test = false

  for _, g in ipairs(god) do
    for _, n in ipairs(Fk:getSameGenerals(g)) do
      table.insertIfNeed(god,n)
    end
  end

  function lzhou_logic:initialize(room)
    GameLogic.initialize(self, room)
    self.role_table = {
      { "lord","renegade","rebel",},
      { "lord","renegade","rebel", "rebel",},
      {"lord", "loyalist", "renegade","rebel", "rebel"},
      { "lord","loyalist", "renegade", "rebel", "rebel", "rebel" },
      { "lord","loyalist", "loyalist", "renegade", "rebel", "rebel", "rebel" },
      { "lord","loyalist", "loyalist", "renegade", "rebel", "rebel", "rebel","rebel"},
      { "lord","loyalist", "loyalist", "renegade", "rebel", "rebel", "rebel","rebel","rebel"},
      { "lord","loyalist", "loyalist", "renegade", "rebel", "rebel", "rebel","rebel","rebel","rebel"},
    }
  end

  function lzhou_logic:prepareForStart()
    local room = self.room
    self:addTriggerSkill(GameRule)
    for _, trig in ipairs(Fk.global_trigger) do
      if trig.name ~= "mobile_effect" then  --关闭手杀特效
        self:addTriggerSkill(trig)
      end
    end
    self.room:sendLog{ type = "$GameStart" }
  end

  function lzhou_logic:prepareDrawPile()
    local room = self.room
    local seed = math.random(2 << 32 - 1)
    local allCardIds = Fk:getAllCardIds()
    local blacklist = {"crossbow","indulgence","wd_rice","diy_restart"}
    local whitelist = {}
    for i = #allCardIds, 1, -1 do
      local card = Fk:getCardById(allCardIds[i])
      local name = card.name
      if (card.is_derived and not table.contains(whitelist, name)) or table.contains(blacklist, name) then
        local id = allCardIds[i]
        table.removeOne(allCardIds, id)
        table.insert(room.void, id)
        room:setCardArea(id, Card.Void, nil)
      end
    room:doBroadcastNotify("PrepareDrawPile", seed)
    end
  
    table.shuffle(allCardIds)
    room.draw_pile = allCardIds
    for _, id in ipairs(room.draw_pile) do
      room:setCardArea(id, Card.DrawPile, nil)
    end
  end
  
  function lzhou_logic:assignRoles()
    local room = self.room
    local n = #room.players
    local roles = self.role_table[n-2]
    table.shuffle(roles)

    local bots_t = {}
    local players_t = {}
    for i = 1, n do
      local p = room.players[i]
      if p.id < 0 then
        table.insert(bots_t,{p.id,i})
      end
      if p.id > 0 then
        table.insert(players_t,{p.id,i})
      end
    end

    if #bots_t >= 1 then
      local lord_t = table.random(bots_t)
      local lord_player = room.players[lord_t[2]]
      lord_player.role = "lord"
      lord_player.role_shown = true
      room:broadcastProperty(lord_player, "role")
      local renegade = true
      for i = 1, n do
        local p = room.players[i]
        if p.role ~= "lord" then
          if p.id < 0 then
             p.role = "renegade"
          else
            p.role = "rebel"
          end
          p.role_shown = true
          room:notifyProperty(p, p, "role")
        end
      end
    else
      --默认主反模式
      for i = 1, n do
        local p = room.players[i]
        p.role = roles[i]
        if p.role == "lord" then
          p.role_shown = true
          room:broadcastProperty(p, "role")
        else
          room:notifyProperty(p, p, "role")
        end
      end
    end
    local rebel = {}
    for _, p in ipairs(room.players) do
      if p.role == "rebel" then
        table.insert(rebel,p)
      end
    end
    for _, p in ipairs(rebel) do
      for _, p2 in ipairs(rebel) do
        if p2 ~= p then
          p:addBuddy(p2)
        end
      end
    end
    local targets = {}
    local renegade = {}
    local rebel = {}
    for _, p in ipairs(room.players) do
      if p.role == "lord" then
        table.insertIfNeed(targets,p)
      end
    end
    for _, p in ipairs(room.players) do
      if p.role == "renegade" then
        table.insertIfNeed(renegade,p)
      end
    end
    for _, p in ipairs(room.players) do
      if p.role == "rebel" then
        table.insertIfNeed(rebel,p)
      end
    end
    local n = #room.players
    if (n == 4 and #rebel == 1) or  (n == 7 and #rebel == 2) or (n == 10 and #rebel == 3) then
    if n >= 4 then
        targets[2] = renegade[1]
        targets[3] = rebel[1]
        targets[4] = renegade[2]
    end
    if n >= 7 then
        targets[5] = renegade[3]
        targets[6] = rebel[2]
        targets[7] = renegade[4]
    end
    if n >= 10 then
        targets[8] = renegade[5]
        targets[9] = rebel[3]
        targets[10] = renegade[6]
    end
    room.players = targets
    local player_circle = {}
    for i = 1, #room.players do
      room.players[i].seat = i
      table.insert(player_circle, room.players[i].id)
    end
    for i = 1, #room.players - 1 do
      room.players[i].next = room.players[i + 1]
    end
    room.players[#room.players].next = room.players[1]
    room:doBroadcastNotify("ArrangeSeats", json.encode(player_circle))
  end
  end
  --选将
  function lzhou_logic:chooseGenerals()
    local room = self.room ---@type Room
    local n = room.settings.generalNum
    local gpile = table.simpleClone(room.general_pile)
    local gpile = table.simpleClone(room.general_pile)
    for _, g in ipairs(gpile) do
      if not table.contains(white,Fk.generals[g].package.extensionName) or table.contains(black,g) then
        table.removeOne(room.general_pile,g)
      end
    end
    table.removeOne(room.general_pile,"mouxusheng")
    table.removeOne(room.general_pile,"joyo__nvwa")
    local lord = {}
    local rebel = {}
    local renegade = {}
    local j
    for _, p in ipairs(room.players) do
      if p.role == "renegade"   then
        table.insert(renegade,p)
      elseif p.role == "lord" then
        table.insert(lord,p)
        j = p
      elseif p.role == "rebel" then
        table.insert(rebel,p)
      end
    end
    room.current = j

    --选将
    for _, p in ipairs(lord) do
        local gens = table.random(lzboss)
        room:setPlayerGeneral(p, gens, true, true)
        local mark = {}
        table.insertIfNeed(mark,gens)
        room:setBanner("@&lzboss",mark)
        room:broadcastProperty(p, "role")
        room:broadcastProperty(p, "general")
        room:broadcastProperty(p, "kingdom")
        room:handleAddLoseSkills(p,"tshu__lanjiang",nil,true)
    end
    for i = 1, #renegade, 1 do
        if i%2 ~= 0 then
            room:setPlayerGeneral(renegade[i], "tshulz__zuogu", true, true)
        elseif i%2 == 0 then
            room:setPlayerGeneral(renegade[i], "tshulz__yougu", true, true)
        end
    end
    for _, p in ipairs(renegade) do
        room:broadcastProperty(p, "role")
        room:broadcastProperty(p, "general")
        room:broadcastProperty(p, "kingdom")
    end
    local gen = {}
    for _, p in ipairs(rebel) do
        local gens = room:getNGenerals(9)
        local skills = {{"tshu_yes1"},{"tshu_yes2"},{"tshu_yes3"},{"tshu_yes4"},{"tshu_yes5"},{"tshu_yes6"},{"tshu_yes7"},{"tshu_yes8"},{"tshu_yes9"}}
        if test and   room.settings.enableDeputy then
            table.insertIfNeed(gens,"mouxusheng")
            table.insert(skills,{"tshu_yes10"})
        end
        table.insert(gen,gens)
        p.request_data = json.encode({
            path = "packages/tshu/qml/ChooseGeneralSkillsBox.qml",
            data = {
              gens,skills, 1, 1, "#tshu__gen-choice", false
            },
          })
          p.default_reply = table.random(skills)
    end
      room:doBroadcastNotify("ShowToast", Fk:translate("lzhou choose general"))
      room:notifyMoveFocus(rebel, "选择武将")
      room:doBroadcastRequest("CustomDialog",rebel)
      
      local g2 = 0
      for _, p in ipairs(rebel) do
        local g = p.reply_ready and json.decode(p.client_reply) or p.default_reply
        g2 = g2 + 1
        local gogen = gen[g2]
        g = table.concat(g)
        local num = string.sub(g, 9)
        num = (tonumber(string.match(num, "%d+")))
        g = gogen[num]
        table.removeOne(gogen,g)
        room:setPlayerGeneral(p, g, true, true)
        p.default_reply = ""
        room:returnToGeneralPile(gogen)
      end
      for _, p in ipairs(rebel) do
        room:broadcastProperty(p, "role")
        room:broadcastProperty(p, "general")
        room:broadcastProperty(p, "kingdom")
        room:handleAddLoseSkills(p,"tshu__leigu&|tshu__zhengdu",nil,true)
        room:addPlayerMark(p,"@ganlu",1)
      end
      room:askForChooseKingdom(rebel)

    --PVEbuff
    for _, p in ipairs(rebel) do
      local choices = {"pvebuff1","pvebuff2","pvebuff3"}
      p.request_data = json.encode({choices, choices, "tshu__buff", "#pvebuff-choice",true})
    end
    room:notifyMoveFocus(room.alive_players,"tshu__buff")
    room:doBroadcastRequest("AskForChoice",rebel)
    
    for _, p in ipairs(rebel) do
      local choice
      if p.reply_ready then
        choice = p.client_reply
      else
        p.client_reply = "pvebuff2"
        choice = "pvebuff2"
      end
      room:sendLog{
        type = "#tshu__buff-quest",
        from = p.id,
        arg = choice,
      }
      if choice == "pvebuff1" then
        room:setPlayerMark(p,"tshu__buff1",1)
        room:setPlayerMark(p,"tshu__buff2",1)
      elseif choice == "pvebuff2" then
        room:setPlayerMark(p,"tshu__buff1",1)
        room:setPlayerMark(p,"tshu__buff3",1)
      elseif choice == "pvebuff3" then
        room:setPlayerMark(p,"tshu__buff3",1)
        room:setPlayerMark(p,"tshu__buff4",1)
      end
    end

    --将灵
    local jl = {"tshujl__zhugeguo","tshujl__lingjv","tshujl__zhouyu","tshujl__guanyu"}
    local jlmark = {}
    local skills = {}
    for _, s in ipairs(jl) do
        table.insert(skills,{s})
    end
    for _, p in ipairs(rebel) do
      p.request_data = json.encode({
    path = "packages/tshu/qml/ChooseGeneralSkillsBox.qml",
    data = {
      jl,skills, 1, 1, "#jl-choice", false
    },
  })
  p.default_reply = table.random(skills)
  end
  room:notifyMoveFocus(rebel, "选择将灵")
  room:doBroadcastRequest("CustomDialog",rebel)
  
  for _, p in ipairs(rebel) do
    local jj = p.reply_ready and json.decode(p.client_reply) or p.default_reply
    room:notifySkillInvoked(p,table.concat(jj),"drawcard")
    for _, s in ipairs(Fk.generals[table.concat(jj)].skills) do
      p:broadcastSkillInvoke(s.name)
      break
    end
    table.insertIfNeed(jlmark,table.concat(jj))
    room:setPlayerMark(p,table.concat(jj),1)
    room:setPlayerMark(p,"@&tshu__jlmark",{table.concat(jj)})
    p.default_reply = ""
  end
    room:setBanner("@&tshu__jl",jlmark)
    room:setBanner("@lzjd","60米")
    room:setBanner("lzjd",60)
    room:setBanner("lz_draw",10)
    room:setBanner("lz_damage",20)
    room:setBanner("lz_cover",20)
    room:setBanner("lz_control",10)
  end

  function lzhou_logic:configureAI()
    for _, p in ipairs(self.room.players) do
      if p.id < 0 then
        p.ai = nil
        p.ai = LangAI:new(p)
      end
    end
  end
  
  return lzhou_logic
end

local test = false
--[[
local function drawInit(room, player, n)
    -- TODO: need a new function to call the UI
    local cardIds = room:getNCards(n)
    player:addCards(Player.Hand, cardIds)
    for _, id in ipairs(cardIds) do
      Fk:filterCard(id, player)
    end
    local move_to_notify = {}   ---@type CardsMoveStruct
    move_to_notify.toArea = Card.PlayerHand
    move_to_notify.to = player.id
    move_to_notify.moveInfo = {}
    move_to_notify.moveReason = fk.ReasonDraw
    for _, id in ipairs(cardIds) do
      table.insert(move_to_notify.moveInfo,
      { cardId = id, fromArea = Card.DrawPile })
    end
    room:notifyMoveCards(nil, {move_to_notify})
  
    for _, id in ipairs(cardIds) do
      room:setCardArea(id, Card.PlayerHand, player.id)
    end
  end
]]
--观看队友手牌
local function Buddy(room)
    local rebel = {}
    for _, p in ipairs(room.players) do
        if p.role == "rebel" then
        table.insert(rebel,p)
      end
    end
    for _, p in ipairs(rebel) do
      for _, p2 in ipairs(rebel) do
        if p2 ~= p then
          p:addBuddy(p2)
        end
      end
    end
end

--发动所有游戏开始时技能
local function restart(player)
  for _, s in ipairs(Fk.generals[player.general]:getSkillNameList()) do
   s = Fk.skills[s]
    if s:isInstanceOf(TriggerSkill) and type(s.events) == "table" and (table.contains(s.events,fk.GameStart) or table.contains(s.events, fk.GamePrepared)) then
      local events = {fk.GamePrepared, fk.GameStart}
      for i = #events, 1, -1 do
        if not table.contains(s.events, events[i]) then
          table.remove(events, i)
        end
      end
      for _, e in ipairs(events) do
        if s:triggerable(e, player, player, nil) then
          s:trigger(e, player, player, nil)
        end
      end
    end
  end
  if player.deputyGeneral and player.deputyGeneral ~= "" then
  for _, s in ipairs(Fk.generals[player.deputyGeneral]:getSkillNameList()) do
  s = Fk.skills[s]
    if s:isInstanceOf(TriggerSkill) and type(s.events) == "table" and (table.contains(s.events,fk.GameStart) or table.contains(s.events, fk.GamePrepared)) then
      local events = {fk.GamePrepared, fk.GameStart}
      for i = #events, 1, -1 do
        if not table.contains(s.events, events[i]) then
          table.remove(events, i)
        end
      end
      for _, e in ipairs(events) do
        if s:triggerable(e, player, player, nil) then
          s:trigger(e, player, player, nil)
        end
      end
    end
  end
  end
end

--调整座位
local function moveSeats(room)
    local targets = {}
    local renegade = {}
    local rebel = {}
    for _, p in ipairs(room.players) do
      if  p.role == "loyalist" then
        table.insertIfNeed(targets,p)
      end
    end
    table.shuffle(targets)
    for _, p in ipairs(room.players) do
      if  p.role == "lord" then
        table.insert(targets,1,p)
      end
    end
    for _, p in ipairs(room.players) do
      if p.role == "rebel" then
        table.insert(targets,p)
      end
    end
    local n = #room.players
    room.players = targets
    local player_circle = {}
    for i = 1, #room.players do
      room.players[i].seat = i
      table.insert(player_circle, room.players[i].id)
    end
    for i = 1, #room.players - 1 do
      room.players[i].next = room.players[i + 1]
    end
    room.players[#room.players].next = room.players[1]
    room:doBroadcastNotify("ArrangeSeats", json.encode(player_circle))
end
local qidian = false
--通关
local function up(room)
    local lzboss = {"tshugod__caoe","tshugod__taoshen","tshugod__hebo","tshugod__yuershen"}
    local jl = {"tshujl__zhugeguo","tshujl__lingjv","tshujl__zhouyu","tshujl__guanyu","tshujl__caoying","tshujl__guansuo",
    "tshujl__nianshou","tshujl__zhaoxiang","tshujl__xiaosha","tshujl__caochun","tshujl__zhouyi"}
    local have = room:getBanner("@&lzboss")
    for _, name in ipairs(have) do
      table.removeOne(lzboss,name)
    end
    local boss = table.random(lzboss)
    table.insertIfNeed(have,boss)
    room:setBanner("@&lzboss",have)
    local n = #room:getBanner("@&lzboss")
    local nn = n - 1
    room:doBroadcastNotify("ShowToast", "恭喜成功通过第"..nn.."关！")
    room:delay(300)
    local lord
    local renegade = {}
    local rebel = {}
    for _, p in ipairs(room.players) do
        if p.role == "lord" then
            lord = p
        elseif p.role == "rebel" then
            table.insert(rebel,p)
        elseif p.role == "renegade" then
            table.insert(renegade,p)
        end
    end
    lord:bury()
    local to_rm = table.filter(lord.player_skills, function(s)
        return not s.attached_equip and s.name[#s.name] ~= "&" -- 不是装备技和按钮的全图图了
       end)
    room:handleAddLoseSkills(lord, table.concat(
         table.map(to_rm, function(s) return "-" .. s.name end), "|"), nil, true)
    room:resumePlayerArea(lord, {Player.WeaponSlot, Player.ArmorSlot, Player.OffensiveRideSlot, Player.DefensiveRideSlot, Player.TreasureSlot, Player.JudgeSlot}) -- 全部恢复

    room:changeHero(lord, boss, false, false, true)
    room:revivePlayer(lord, false)
    room:setPlayerProperty(lord, "kingdom", Fk.generals[boss].kingdom)
    room:changeMaxHp(lord,Fk.generals[boss].maxHp*n)
    room:setPlayerProperty(lord, "hp", lord.maxHp)
    --drawInit(room,lord,n*10)
    lord:drawCards(n*10)
    room:handleAddLoseSkills(lord,"tshu__lanjiang",nil,true)
    for _, p in ipairs(renegade) do
        p:bury()
        room:revivePlayer(p, false)
        room:changeMaxHp(p,Fk.generals[p.general].maxHp*(n-1))
        room:setPlayerProperty(p, "hp", p.maxHp)
    end
    --武将
    for _, p in ipairs(rebel) do
        if not p.dead then
            room:addPlayerMark(p,"@ganlu",1)
        end
        local to_rm2 = table.filter(p.player_skills, function(s)
          return not s.attached_equip and s.name[#s.name] ~= "&" -- 不是装备技和按钮的全图图了
         end)
        room:handleAddLoseSkills(p, table.concat(
           table.map(to_rm2, function(s) return "-" .. s.name end), "|"), nil, true)
        room:handleAddLoseSkills(p,"tshu__leigu&|tshu__zhengdu",nil,true)
        room:resumePlayerArea(p, {Player.WeaponSlot, Player.ArmorSlot, Player.OffensiveRideSlot, Player.DefensiveRideSlot, Player.TreasureSlot, Player.JudgeSlot})
    end
    local gen = {}
    for _, p in ipairs(rebel) do
        local gens = room:getNGenerals(9)
        local skills = {{"tshu_yes1"},{"tshu_yes2"},{"tshu_yes3"},{"tshu_yes4"},{"tshu_yes5"},{"tshu_yes6"},{"tshu_yes7"},{"tshu_yes8"},{"tshu_yes9"}}
        if test and   room.settings.enableDeputy then
            table.insertIfNeed(gens,"mouxusheng")
            table.insert(skills,{"tshu_yes10"})
        end
        table.insert(gen,gens)
        p.request_data = json.encode({
            path = "packages/tshu/qml/ChooseGeneralSkillsBox.qml",
            data = {
              gens,skills, 1, 1, "#tshu__gen-choice", false
            },
          })
          p.default_reply = table.random(skills)
    end
      room:doBroadcastNotify("ShowToast", "选择一个武将替换为新武将")
      room:notifyMoveFocus(rebel, "选择武将")
      room:doBroadcastRequest("CustomDialog",rebel)
      
      local g2 = 0
      for _, p in ipairs(rebel) do
        local g = p.reply_ready and json.decode(p.client_reply) or p.default_reply
        g = table.concat(g)
        g2 = g2 + 1
        local gogen = gen[g2]
        local num = string.sub(g, 9)
        num = (tonumber(string.match(num, "%d+")))
        g = gogen[num]
        table.removeOne(gogen,g)
          room:changeHero(p, g, false, false, true)
          room:revivePlayer(p, false)
          p:reset()
            room:setPlayerProperty(p, "kingdom", Fk.generals[g].kingdom)
            room:setPlayerProperty(p, "hp", Fk.generals[g].hp)
        p.default_reply = ""
        room:returnToGeneralPile(gogen)
      end
      for _, p in ipairs(rebel) do
        room:broadcastProperty(p, "general")
        room:broadcastProperty(p, "kingdom")
      end
      room:askForChooseKingdom(rebel)
      --将灵
      local gjl = {}
      if n == 2 then
        gjl = {"tshujl__caoying","tshujl__guansuo","tshujl__xiaosha"}
      elseif n == 3 then
        gjl = {"tshujl__caochun","tshujl__zhaoxiang","tshujl__nianshou","tshujl__zhouyi"}
      elseif n == 4 then
        gjl = table.random(jl,4)
        table.insertIfNeed(gjl,"tshujl__zhaoyun")
      end
    local jlmark = {}
    local skills = {}
    for _, s in ipairs(gjl) do
        table.insert(skills,{s})
    end
    for _, p in ipairs(rebel) do
        for _, j in ipairs(jl) do
            room:setPlayerMark(p,j,0)
        end
      p.request_data = json.encode({
    path = "packages/tshu/qml/ChooseGeneralSkillsBox.qml",
    data = {
      gjl,skills, 1, 1, "#jl-choice", false
    },
  })
  p.default_reply = table.random(skills)
  end
  room:doBroadcastNotify("ShowToast", "选择一个新将灵")
  room:notifyMoveFocus(rebel, "选择将灵")
  room:doBroadcastRequest("CustomDialog",rebel)
  
  for _, p in ipairs(rebel) do
    local jj = p.reply_ready and json.decode(p.client_reply) or p.default_reply
    room:notifySkillInvoked(p,table.concat(jj),"drawcard")
    for _, s in ipairs(Fk.generals[table.concat(jj)].skills) do
      p:broadcastSkillInvoke(s.name)
      break
    end
    table.insertIfNeed(jlmark,table.concat(jj))
    room:setPlayerMark(p,table.concat(jj),1)
    room:setPlayerMark(p,"@&tshu__jlmark",{table.concat(jj)})
    p.default_reply = ""
  end
  room:setBanner("@&tshu__jl",jlmark)

  --结算争渡
  local m = (tonumber(string.match(room:getBanner("@lzjd") or 0, "%d+"))) + (room:getBanner("lzjd2") or 0)
  for _, p in ipairs(rebel) do
    room:changeMaxHp(p,m//400)
    room:changeHp(p,m//200,nil,nil)
    --drawInit(room,p,m//100)
    p:drawcard(m//100)
  end
  room:changeMaxHp(lord,-m//200)
  room:setBanner("lzjd2",(room:getBanner("lzjd2") or 0) + m)
  room:doBroadcastNotify("ShowToast", "已结算本轮龙舟进度")
  room:setBanner("@lzjd","60米")
  room:setBanner("lzjd",60)
    room:setBanner("lz_draw",10)
    room:setBanner("lz_damage",20)
    room:setBanner("lz_cover",20)
    room:setBanner("lz_control",10)


local rc = room.current
room.logic:trigger(fk.GamePrepared,rc)
room.logic:trigger(fk.GameStart, rc)
  

    lord:gainAnExtraTurn(true)
    room.logic:breakTurn()
end

--登神
local function endup(room)
  local lzboss = {"tshugod__caoe","tshugod__taoshen","tshugod__hebo","tshugod__yuershen"}
  local godboss = {"tshugod__kuafu","tshugod__shaohao","tshugod__xuannv","tshugod__hanba","tshugod__yanluowang"}
  table.shuffle(godboss)
  table.shuffle(lzboss)
  local jl = {"tshujl__zhugeguo","tshujl__lingjv","tshujl__zhouyu","tshujl__guanyu","tshujl__caoying","tshujl__guansuo",
  "tshujl__nianshou","tshujl__zhaoxiang","tshujl__xiaosha","tshujl__caochun","tshujl__zhaoyun","tshujl__zhouyi"}
  --moveSeats(room)
  local tlord
  local lords = {}
  local rebel = {}
  for _, p in ipairs(room.players) do
      if p.role == "lord" then
          tlord = p
          table.insert(lords,p)
      elseif p.role == "rebel" then
          table.insert(rebel,p)
      elseif p.role == "renegade" then
          p.role = "loyalist"
          room:broadcastProperty(p, "role")
          table.insert(lords,p)
      end
  end
  local num = math.min(#godboss,#lords)
  for i = 1, num, 1 do
    local lord = lords[i]
    local boss = godboss[i]
  lord:bury()
  local to_rm = table.filter(lord.player_skills, function(s)
      return not s.attached_equip and s.name[#s.name] ~= "&" -- 不是装备技和按钮的全图图了
     end)
  room:handleAddLoseSkills(lord, table.concat(
       table.map(to_rm, function(s) return "-" .. s.name end), "|"), nil, true)
  room:resumePlayerArea(lord, {Player.WeaponSlot, Player.ArmorSlot, Player.OffensiveRideSlot, Player.DefensiveRideSlot, Player.TreasureSlot, Player.JudgeSlot}) -- 全部恢复
    
  room:changeHero(lord, boss, false, false, true)
  room:revivePlayer(lord, false)
  room:setPlayerProperty(lord, "kingdom", Fk.generals[boss].kingdom)
  room:changeMaxHp(lord,Fk.generals[boss].maxHp*5)
  room:setPlayerProperty(lord, "hp", lord.maxHp)
  --drawInit(room,lord,5*10)
  lord:drawCards(5*10)
  end
  --武将
  for _, p in ipairs(rebel) do
    p:bury()
    local to_rm2 = table.filter(p.player_skills, function(s)
      return not s.attached_equip and s.name[#s.name] ~= "&" -- 不是装备技和按钮的全图图了
     end)
    room:handleAddLoseSkills(p, table.concat(
       table.map(to_rm2, function(s) return "-" .. s.name end), "|"), nil, true)
       room:resumePlayerArea(p, {Player.WeaponSlot, Player.ArmorSlot, Player.OffensiveRideSlot, Player.DefensiveRideSlot, Player.TreasureSlot, Player.JudgeSlot})
       p:reset()
  end
  local gen
  if #rebel == 1 then
    gen = {lzboss}
  elseif #rebel == 2 then
    gen = {{lzboss[1],lzboss[2]},{lzboss[3],lzboss[4]}}
  elseif #rebel == 3 then
    gen = {{lzboss[1]},{lzboss[2]},{lzboss[3]}}
  end
  local a = 1
  for _, p in ipairs(rebel) do
      local gens = gen[a]
      a = a + 1
      if  test and  room.settings.enableDeputy then
        table.insertIfNeed(gens,"mouxusheng")
    end
      local skills = {}
      for _, s in ipairs(gens) do
          table.insert(skills,{s})
      end
      p.request_data = json.encode({
          path = "packages/tshu/qml/ChooseGeneralSkillsBox.qml",
          data = {
            gens,skills, 1, 1, "#tshu__gen-choice", false
          },
        })
        p.default_reply = table.random(skills)
      
  end
    room:doBroadcastNotify("ShowToast", "选择一个武将替换为新武将")
    room:notifyMoveFocus(rebel, "选择武将")
    room:doBroadcastRequest("CustomDialog",rebel)
    
    for _, p in ipairs(rebel) do
      local g = p.reply_ready and json.decode(p.client_reply) or p.default_reply
      g = table.concat(g)
        room:changeHero(p, g, false, false, true)
        room:revivePlayer(p, false)
          room:setPlayerProperty(p, "kingdom", Fk.generals[g].kingdom)
          room:setPlayerProperty(p, "hp", Fk.generals[g].hp)
      p.default_reply = ""
      table.removeOne(room.general_pile,p.general)
    end
    for _, p in ipairs(rebel) do
      room:broadcastProperty(p, "general")
      room:broadcastProperty(p, "kingdom")
      room:handleAddLoseSkills(p,"-tshu__leigu&|-tshu__zhengdu",nil,true)
    end
    room:askForChooseKingdom(rebel)
    room:setBanner("@&tshu__jl",0)

--结算争渡
local m = (tonumber(string.match(room:getBanner("@lzjd") or 0, "%d+"))) + (room:getBanner("lzjd2") or 0)
for _, p in ipairs(rebel) do
  room:changeMaxHp(p,m//200)
  room:changeHp(p,m//200,nil,nil)
  --drawInit(room,p,m//100)
  p:drawcard(m//100)
end
for _, p in ipairs(lords) do
  room:changeMaxHp(p,-m//200)
end

room:setBanner("lzjd2",(room:getBanner("lzjd2") or 0) + m)
--room:doBroadcastNotify("ShowToast", "已结算本轮龙舟进度")
room:setBanner("@lzjd",0)
room:setBanner("lzjd",0)
room:setBanner("lz_draw",0)
room:setBanner("lz_damage",0)
room:setBanner("lz_cover",0)
room:setBanner("lz_control",0)
room:setBanner("@&lzboss",0)
room:setBanner("@@deng_god",1)


local rc = room.current
room.logic:trigger(fk.GamePrepared,rc)
room.logic:trigger(fk.GameStart, rc)
room:doBroadcastNotify("ShowToast", "登神：向天书诸神证明江海的实力。")
room:delay(800)
local tianq2 = {"tshu__julang2","tshu__dayu2","tshu__leiyu2","tshu__kuangfeng2"}
local tq = table.random(tianq2)
room:setBanner("@[:]lzhou__tianqi",tq)
room:doBroadcastNotify("ShowToast", "本轮天气为"..Fk:translate(tq))
room:delay(500)
for _, p in ipairs(lords) do
  p:gainAnExtraTurn(true)
end
  room.logic:breakTurn()
end

local lanjiang = fk.CreateTriggerSkill{
    name = "tshu__lanjiang",
    mute = true,
    frequency = Skill.Compulsory,
    events = {fk.AfterCardsMove,fk.Damaged,"fk.lanjiang-card","fk.lanjiang-damage",fk.TurnEnd},
    can_trigger = function(self, event, target, player, data)
      if not player:hasSkill(self) then return end
      if event == fk.AfterCardsMove then
      local n = 0
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              n = n + 1
            end
          end
        end
      end
      self.cost_data = n
      return n > 0
    elseif event == fk.Damaged then
            return target == player and player:hasSkill(self)
    elseif event == "fk.lanjiang-card" then
        return target == player and player:hasSkill(self) and player:getMark("tshu__lanjiang-card") >= 5
    elseif event == "fk.lanjiang-damage" then
        return target == player and player:hasSkill(self) and player:getMark("tshu__lanjiang-damage") >= 5
    elseif event == fk.TurnEnd then
        return target.role ~= "renegade" and player:hasSkill(self)
    end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.AfterCardsMove then
        room:addPlayerMark(player,"tshu__lanjiang-card",self.cost_data)
        room.logic:trigger("fk.lanjiang-card", player, { name = "tshu__lanjiang-card", num = self.cost_data})
      elseif event == fk.Damaged then
        room:addPlayerMark(player,"tshu__lanjiang-damage",data.damage)
        room.logic:trigger("fk.lanjiang-damage", player, { name = "tshu__lanjiang-damage", num = data.damage})
    elseif event == "fk.lanjiang-card" then
        for i = 1, 999, 1 do
            if player:getMark("tshu__lanjiang-card") < 5 then break end
            player:broadcastSkillInvoke(self.name)
            room:notifySkillInvoked(player,self.name,"drawcard")
            room:removePlayerMark(player,"tshu__lanjiang-card",5)
            local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick",1,"allPiles")
            if #cards > 0 then
                room:moveCards({
                ids = cards,
                to = player.id,
                toArea = Card.PlayerHand,
                moveReason = fk.ReasonJustMove,
                proposer = player.id,
                skillName = self.name,
                })
            end
            local cards2 = room:getCardsFromPileByRule(".|.|.|.|.|basic",1,"allPiles")
            if #cards2 > 0 then
                room:moveCards({
                ids = cards2,
                to = player.id,
                toArea = Card.PlayerHand,
                moveReason = fk.ReasonJustMove,
                proposer = player.id,
                skillName = self.name,
                })
            end
            local cards3 = room:getCardsFromPileByRule(".|.|.|.|.|equip",1,"allPiles")
            if #cards3 > 0 then
                room:moveCards({
                ids = cards3,
                to = player.id,
                toArea = Card.PlayerHand,
                moveReason = fk.ReasonJustMove,
                proposer = player.id,
                skillName = self.name,
                })
            end
        end
    elseif event == "fk.lanjiang-damage" then
        for i = 1, 999, 1 do
            if player:getMark("tshu__lanjiang-damage") < 5 then break end
            player:broadcastSkillInvoke(self.name)
            room:notifySkillInvoked(player,self.name,"control")
            room:removePlayerMark(player,"tshu__lanjiang-damage",5)
            for _, p in ipairs(room.alive_players) do
                if p.role == "rebel" and not p:isNude() then
                    local cards = p:getCardIds("he")
                    room:moveCardTo(table.random(cards),Card.DiscardPile,player,fk.ReasonDiscard)
                end
            end
        end
    elseif event == fk.TurnEnd then
        room:addPlayerMark(player,"@tshu__lanjiang",1)
    end
    end,
}
local lanjiang_buff = fk.CreateProhibitSkill{
    name = "#tshu__lanjiang_buff",
    frequency = Skill.Compulsory,
    is_prohibited = function(self, from, to, card)
        return (from:hasSkill(self) and to.role == "renegade") or (from:getMark("tshu__lanjiang-turn") > 0 and from ~= to)
    end,
}
local lanjiang_distance = fk.CreateDistanceSkill{
    name = "#tshu__tanjiang_distance",
    frequency = Skill.Compulsory,
    correct_func = function(self, from, to)
    if from.role == "lord" and from:hasSkill(self) and to.role == "rebel"  then
        return -from:getMark("@tshu__lanjiang")
      end
    end,
}
lanjiang:addRelatedSkill(lanjiang_distance)
lanjiang:addRelatedSkill(lanjiang_buff)
Fk:addSkill(lanjiang)
Fk:loadTranslationTable{
    ["tshu__lanjiang"] = "澜江",
    [":tshu__lanjiang"] = "锁定技，每当你累计失去5张牌，你从牌堆弃牌堆获得每个类型牌各一张；每当你累计受到5点伤害，你令所有地方角色随机弃置一张牌;每回合结束时，你计算与其他角色距离-1。",
    ["@tshu__lanjiang"] = "澜江",
    ["#tshu__lanjiang_buff"] = "澜江",
}


local leigu = fk.CreateActiveSkill{
    name = "tshu__leigu&",
    card_num = 0,
    card_filter = Util.FalseFunc,
    target_num = 0,
    target_filter = Util.FalseFunc,
    prompt = "消耗一枚“争渡”进行擂鼓：触发一个随机效果。",
    can_use = function(self, player)
        return  player:getMark("@lzhou__zd") > 0 
    end,
    on_use = function(self, room, effect)
      local player = room:getPlayerById(effect.from)
      player:broadcastSkillInvoke("tshu__jisheng")
      room:removePlayerMark(player,"@lzhou__zd",1)
      local r = math.random(1,4)
      local l
      for _, p in ipairs(room.alive_players) do
        if p.role == "lord" then
            l = p
        end
      end
      local num = room:getBanner("@&lzboss") and #room:getBanner("@&lzboss") or 1
      local n = ((tonumber(string.match(room:getBanner("@lzjd") or 0, "%d+"))) + (room:getBanner("lzjd2") or 0))//(num*100)
      n = math.max(1,n)
      if r == 1 then
        room:doBroadcastNotify("ShowToast","擂鼓效果：摸"..n.."张牌")
        player:drawCards(n,self.name)
      elseif r == 2 then
        room:doBroadcastNotify("ShowToast","擂鼓效果：令BOSS失去"..n.."点体力")
        room:loseHp(l,n,self.name)
      elseif r == 3 then
        room:doBroadcastNotify("ShowToast","擂鼓效果：令BOSS弃置"..n.."张牌")
        room:askForDiscard(l,n,n,true,self.name,false)
      elseif r == 4 then
        room:doBroadcastNotify("ShowToast","擂鼓效果：回复"..n.."点体力")
        room:recover({
            who = player,
            num = math.min(n,player.maxHp - player.hp),
            recoverBy = player,
            skillName = self.name
          })
      end
    end,
}
local zhengdu = fk.CreateDistanceSkill{
    name = "tshu__zhengdu",
    frequency = Skill.Compulsory,
    correct_func = function(self, from, to)

    local n = (tonumber(string.match(Fk:currentRoom():getBanner("@lzjd") or 0, "%d+")))//100
      if from.role == "rebel" and from:hasSkill(self) and to.role == "lord" then
        return -n
      elseif from.role == "lord" and to:hasSkill(self) and to.role == "rebel" then
        return n
      end
    end,
}
local zhengdu_buff = fk.CreateProhibitSkill{
  name = "#tshu__zhengdu_buff",
  frequency = Skill.Compulsory,
  is_prohibited = function(self, from, to, card)
      return to:getMark("tshu__lanjiang-turn") > 0 and from.role == "lord"
  end,
}
zhengdu:addRelatedSkill(zhengdu_buff)
Fk:addSkill(leigu)
Fk:addSkill(zhengdu)
Fk:loadTranslationTable{
    ["tshu__leigu&"] = "擂鼓",
    [":tshu__leigu&"] = "出牌阶段，你可以消耗一枚“争渡”标记进行擂鼓，擂鼓会触发一个随机效果："..
    "<br><font color='grey'>效果一：摸X张牌；</font>"..
    "<br><font color='grey'>效果二：令BOSS失去X点体力；</font>"..
    "<br><font color='grey'>效果三：令BOSS弃置X张牌；</font>"..
    "<br><font color='grey'>效果四：回复X点体力；</font>"..
    "<br>（X为累计龙舟进度/关卡数*100,向下取整)",

    ["tshu__zhengdu"] = "争渡",
    [":tshu__zhengdu"] = "锁定技，你计算与BOSS距离-X，BOSS计算与你距离+X。（X为龙舟进度/100,向下取整)",
}


local lzhou_rule = fk.CreateTriggerSkill{
  name = "#lzhou_rule",
  priority = 0.001,
  refresh_events = {fk.DrawInitialCards, fk.GameOverJudge, fk.BuryVictim, fk.GameStart,fk.RoundEnd,fk.Damage,fk.HpRecover,fk.AfterCardsMove,"fk.lzjd",fk.TurnStart,fk.TurnEnd,fk.RoundStart,fk.AskForPeachesDone,fk.DamageCaused,fk.DrawNCards},
  can_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then return false end
        return target == player and player.role == "rebel" and data.to and data.to.role ~= player.role and player.phase ~= Player.NotActive and (not room:getBanner("lz_damage-turn") or room:getBanner("lz_damage-turn") < 30)
    elseif event == fk.HpRecover then
      if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then return false end
        return target == player and player.role == "rebel" and player.phase ~= Player.NotActive and (not room:getBanner("lz_cover-turn") or room:getBanner("lz_cover-turn") < 30)
    elseif event == fk.AfterCardsMove then
      if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then return false end
        local n = 0
        local m = 0
        for _, move in ipairs(data) do
            if  move.proposer and room:getPlayerById(move.proposer).role == "rebel" and room:getPlayerById(move.proposer).phase == Player.Play and room:getPlayerById(move.proposer).phase ~= Player.NotActive then
              if move.toArea == Card.PlayerHand then
                for _, info in ipairs(move.moveInfo) do
                  if info.fromArea == Card.DrawPile or info.toArea == Card.DiscardPile  then
                    m = m + 1
                  end
                end
              end
            end
          end
        if m > 0 and (not room:getBanner("lz_draw-turn") or room:getBanner("lz_draw-turn")< 20) then
            self.cost_data = {"draw",m}
            return true
        end
        for _, move in ipairs(data) do
            if (move.moveReason == fk.ReasonDiscard or move.moveReason == fk.ReasonPrey) and move.proposer and room:getPlayerById(move.proposer).role == "rebel" and room:getPlayerById(move.proposer).phase == Player.Play and room:getPlayerById(move.proposer).phase ~= Player.NotActive then
              if move.from and room:getPlayerById(move.from).role ~= "rebel" and  move.proposer and move.from ~= move.proposer then
                for _, info in ipairs(move.moveInfo) do
                  if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) then
                    n = n + 1
                  end
                end
              end
            end
          end
        if n > 0 and (not room:getBanner("lz_control-turn") or room:getBanner("lz_control-turn") < 20 )then
            self.cost_data = {"control",n}
            return true
        end
        return false
    elseif event == "fk.lzjd" then
      if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then return false end
        return room:getBanner("lzjd") and room:getBanner("lzjd") >= 100 
    elseif event == fk.TurnStart then
      if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then return false end
        return  #room:getBanner("@&lzboss") == 1 and room:getTag("RoundCount") == 1 and target == player and player.role == "lord" 
    elseif event == fk.TurnEnd then
        return (not room:getBanner("@@deng_god") or room:getBanner("@@deng_god") == 0 )
    elseif event == fk.AskForPeachesDone then
      if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then return false end
        return target == player and player.role == "rebel" and player.hp < 1
    elseif event == fk.DamageCaused  then
      return room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 and target == player 
    elseif  event == fk.DrawNCards then
      return room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 and target == player 
    else
      return target == player
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local body
    local nmark = {"tshu__tianshu","tshu__buff1","tshu__buff2","tshu__buff3","tshu__buff4","tshu__win","@ganlu","@lzhou__zd"}
    if room:getBanner("@&tshu__jl")  and #room:getBanner("@&tshu__jl")  > 0 then
      local gjl = room:getBanner("@&tshu__jl") 
      table.insertTable(nmark,gjl)
    end
    if event == fk.BuryVictim or event == fk.GameOverJudge then
      body = room:getPlayerById(data.who)
    end
    if event == fk.DrawInitialCards then
      if player.role == "renegade" then
        data.num = 0
      elseif player.role == "lord" then
        data.num = player.hp
      else
        data.num = 5
      end
    elseif event == fk.GameOverJudge then
      room:setTag("SkipGameRule", true)
      if  (body.role == "lord"  or body.role == "loyalist") and (not room:getBanner("@@deng_god") or room:getBanner("@@deng_god") == 0) then return end
      if  body.role == "renegade"  then  return end
      local nowin = false
      for _, p in ipairs(room.alive_players) do
        if p.role == "rebel" then
          nowin = true
        end
        if nowin then break end
      end
      if nowin and body.role == "rebel" then 
        return
      end
      local nowin2 = false
      for _, p in ipairs(room.alive_players) do
        if p.role == "lord" or p.role == "loyalist" then
          nowin2 = true
        end
        if nowin2 then break end
      end
      if (body.role == "lord"  or body.role == "loyalist") and nowin2 then return end
      if(body.role == "lord"  or body.role == "loyalist") then
        room:doBroadcastNotify("ShowToast", "恭喜！登神成功！")
        room:doBroadcastNotify("ShowToast", "恭喜！登神成功！！")
        room:doBroadcastNotify("ShowToast", "恭喜！登神成功！！！")
        room:gameOver("rebel")
      else
        if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then
            room:doBroadcastNotify("ShowToast", Fk:translate("#lzhou__lordwin"))
        else
            room:doBroadcastNotify("ShowToast", Fk:translate("#tshu__lordwin"))
        end
        room:gameOver("lord")
      end
      
      return true
    elseif event == fk.GameStart then
      local n = #room.players
      local bots_t = {}
      local players_t = {}
      for i = 1, n do
        local p = room.players[i]
        if p.id < 0 then
          table.insert(bots_t,{p.id,i})
        end
        if p.id > 0 then
          table.insert(players_t,{p.id,i})
        end
      end
      if (n ~= 4 and n~= 7 and n ~= 10) or (#players_t ~= 1 and n == 4) or (#players_t ~= 2 and n == 7) or (#players_t ~= 3 and n == 10) then
        if #players_t == 1 then
          room:doBroadcastNotify("ShowToast", "请开4人房")
        elseif #players_t == 2 then
          room:doBroadcastNotify("ShowToast", "请开7人房")
        elseif #players_t == 3 then
          room:doBroadcastNotify("ShowToast", "请开10人房")
        else
          room:doBroadcastNotify("ShowToast", "请保证真人不超过3名")
        end
        room:gameOver("")
        return
      end
      for _, p in ipairs(room.players) do
        if p.role == "rebel" and Fk.generals[p.general].package.extensionName == "tshu" then
          room:doBroadcastNotify("ShowToast", "请不要选择天书工作人员")
          room:gameOver("")
        end
      end
      --moveSeats(room)
      room:delay(300)
      room:doBroadcastNotify("ShowToast", "在第10轮结束前击杀BOSS并尽量增加龙舟进度")
      room:delay(300)
      ----电脑死亡
    elseif event == fk.BuryVictim and (body.role == "lord" or body.role == "loyalist") then
      room:setTag("SkipGameRule", true)
      body:bury()
      if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then
        room:doBroadcastNotify("ShowToast", "天书 "..Fk:translate(body.general).." 已陨落。")
      end
      if room:getBanner("@&lzboss") and #room:getBanner("@&lzboss") < 4 then
        up(room)
      elseif room:getBanner("@&lzboss") and #room:getBanner("@&lzboss") == 4 then
        endup(room)
      end
      ---玩家死亡换将
    elseif event == fk.BuryVictim and body.role == "rebel"   then
      room:setTag("SkipGameRule", true)
      body:setCardUseHistory("")
      body:setSkillUseHistory("")
      body:throwAllCards()
      for name, _ in pairs(body.mark) do
        if not table.contains(nmark,name) then
          room:setPlayerMark(body, name, 0)
        end
      end
      body:clearPiles()
      body:reset()
      if  room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then
        room:doBroadcastNotify("ShowToast", "江神 "..Fk:translate(body.general).." 已陨落。")
      else
        room:doBroadcastNotify("ShowToast", "等待队友击杀BOSS复活。")
      end
    elseif event == fk.RoundEnd then
        if room:getTag("RoundCount") == 10 then
            room:doBroadcastNotify("ShowToast", "10轮结束，争渡失败。")
            for _, p in ipairs(room.alive_players) do
              if p.role == "rebel" then
                room:killPlayer({who = p.id})
              end
            end
        end
    elseif event == fk.HpRecover then
        for i = 1, data.num*4, 1 do
            if room:getBanner("lz_cover-turn") and room:getBanner("lz_cover-turn") >= 30 then break end
            room:setBanner("@lzjd",((tonumber(string.match(room:getBanner("@lzjd") or 0, "%d+"))) + 1).."米")
            room:setBanner("lz_cover",(room:getBanner("lz_cover") or 0) + 1)
            room:setBanner("lz_cover-turn",(room:getBanner("lz_cover-turn") or 0) + 1)
            room:setBanner("lzjd",(room:getBanner("lzjd") or 0) + 1)
            room.logic:trigger("fk.lzjd", player, { name = "@lzjd", num = 1})
        end
    elseif event == fk.Damage then
      local n = data.damage
        for i = 1, n*4, 1 do
            if room:getBanner("lz_damage-turn") and room:getBanner("lz_damage-turn") >= 20 then break end
            room:setBanner("@lzjd",((tonumber(string.match(room:getBanner("@lzjd") or 0, "%d+"))) + 1).."米")
            room:setBanner("lz_damage",(room:getBanner("lz_damage") or 0) + 1)
            room:setBanner("lz_damage-turn",(room:getBanner("lz_damage-turn") or 0) + 1)
            room:setBanner("lzjd",(room:getBanner("lzjd") or 0) + 1)
            room.logic:trigger("fk.lzjd", player, { name = "@lzjd", num = 1})
        end
    elseif event == fk.AfterCardsMove then
        if self.cost_data[1] == "draw" then
            for i = 1, self.cost_data[2], 1 do
                if room:getBanner("lz_draw-turn") and room:getBanner("lz_draw-turn") >= 30 then break end
                room:setBanner("@lzjd",((tonumber(string.match(room:getBanner("@lzjd") or 0, "%d+"))) + 1).."米")
                room:setBanner("lz_draw",(room:getBanner("lz_draw") or 0) + 1)
                room:setBanner("lz_draw-turn",(room:getBanner("lz_draw-turn") or 0) + 1)
                room:setBanner("lzjd",(room:getBanner("lzjd") or 0) + 1)
                room.logic:trigger("fk.lzjd", player, { name = "@lzjd", num = 1})
            end
        elseif self.cost_data[1] == "control" then
            for i = 1, self.cost_data[2], 1 do
                if  room:getBanner("lz_control-turn") and  room:getBanner("lz_control-turn") >= 30 then break end
                room:setBanner("@lzjd",((tonumber(string.match(room:getBanner("@lzjd") or 0, "%d+"))) + 1).."米")
                room:setBanner("lz_control",(room:getBanner("lz_control") or 0) + 1)
                room:setBanner("lz_control-turn",(room:getBanner("lz_control-turn") or 0) + 1)
                room:setBanner("lzjd",(room:getBanner("lzjd") or 0) + 1)
                room.logic:trigger("fk.lzjd", player, { name = "@lzjd", num = 1})
            end
        end
    elseif event == "fk.lzjd" then
        room:setBanner("lzjd",(room:getBanner("lzjd") or 0) - 100)
        for _, p in ipairs(room.alive_players) do
            if p.role == "rebel" then
                room:addPlayerMark(p,"@lzhou__zd",1)
            end
        end
    elseif event == fk.TurnStart then
        room:doBroadcastNotify("ShowToast", "首轮保护：BOSS本回合无法指定其他角色为目标")
        for _, p in ipairs(room.alive_players) do
                room:setPlayerMark(p,"tshu__lanjiang-turn",1)
        end
    elseif event == fk.TurnEnd then
      room:setBanner("lz_draw-turn",0)
      room:setBanner("lz_damage-turn",0)
      room:setBanner("lz_cover-turn",0)
      room:setBanner("lz_control-turn",0)
      local tar = {}
        for _, p in ipairs(room.players) do
            if p.role == "renegade"  then
                table.insertIfNeed(tar,p)
            end
        end
        if #tar > 0 then
          for _, p in ipairs(tar) do
              room:revivePlayer(p, false)
              room:setPlayerProperty(p, "hp", p.maxHp)
          end
        end
    elseif event == fk.RoundStart then
        local tq = room:getBanner("@[:]lzhou__tianqi")
        local tianq = {"tshu__qingtian","tshu__dawu","tshu__yintian","tshu__lieri","tshu__leidian"}
        if room:getBanner("@@deng_god") and room:getBanner("@@deng_god") == 1 then
          local tianq2 = {"tshu__julang2","tshu__dayu2","tshu__leiyu2","tshu__kuangfeng2"}
          table.removeOne(tianq2,tq)
          tq = table.random(tianq2)
        else
          local tqt = tq
          if room:getTag("RoundCount") == 1 then
              tq = "tshu__qingtian"
          else
            table.removeOne(tianq,tq)
            tq = table.random(tianq)
            if room:getTag("RoundCount") > 5 then
                local lord
                for _, p in ipairs(room.players) do
                    if p.role == "lord" then
                        lord = p.general
                        break
                    end
                end
                if lord == "tshugod__taoshen" and tqt ~= "tshu__julang" then
                    tq = table.random({tq,"tshu__julang"})
                elseif lord == "tshugod__caoe" and tqt ~= "tshu__dayu" then
                    tq = table.random({tq,"tshu__dayu"})
                elseif lord == "tshugod__hebo" and tqt ~= "tshu__leiyu" then
                    tq = table.random({tq,"tshu__leiyu"}) 
                elseif lord == "tshugod__yuershen" and tqt ~= "tshu__kuangfeng" then
                    tq = table.random({tq,"tshu__kuangfeng"})       
                end
            end
          end
        end
        room:setBanner("@[:]lzhou__tianqi",tq)
        room:doBroadcastNotify("ShowToast", "本轮天气为"..Fk:translate(tq))
        room:delay(500)
    elseif event == fk.AskForPeachesDone then
        if player:getMark("@ganlu") > 0 then
            room:removePlayerMark(player,"@ganlu",1)
            room:notifySkillInvoked(player, "甘露", "support")
            room:recover({
                who = player,
                num = math.min(5, player.maxHp) - player.hp,
                recoverBy = player,
                skillName = self.name,
              })
            player:drawCards(5, self.name)
        else
            local can = false
            for _, p in ipairs(room.alive_players) do
                if can  then break end
                if p.role == "rebel" and p:getMark("@ganlu") > 0 then
                    can = room:askForSkillInvoke(p,"甘露",nil,"是否消耗一枚“甘露”拯救 %dest ？::"..player.id)
                end
                if can then
                    room:removePlayerMark(p,"@ganlu",1)
                    room:notifySkillInvoked(player, "甘露", "support")
                    room:recover({
                        who = player,
                        num = math.min(5, player.maxHp) - player.hp,
                        recoverBy = player,
                        skillName = self.name,
                        })
                    player:drawCards(5, self.name)
                    break
                end
            end
        end
    elseif event == fk.DamageCaused then
      if player.role == "rebel" then
        data.damage = data.damage + ((room:getBanner("lzjd2") or 0)//500)
      else
        data.damage = data.damage + 2
      end
    elseif event == fk.DrawNCards then
      if player.role == "rebel" then
        data.n = data.n + ((room:getBanner("lzjd2") or 0)//500)
      else
        data.n = data.n + 5
      end
    end
  end,
}
local lzhou_mode = fk.CreateGameMode{
  name = "lzhou_mode",
  minPlayer = 4,
  maxPlayer = 10,
  rule = lzhou_rule,
  logic = lzhou_getLogic,
  surrender_func = function(self, playedTime)
    return { { text = "tshu_allcan", passed = true } }
  end,
}

Fk:loadTranslationTable{
  ["lzhou_mode"] = "龙舟激浪",
  ["lzhou choose general"] = "选择一个武将",
  ["tshu_allcan"] = "你随时都可以投降",
  ["#tshu__gen-choice"] = "武将选择",
  ["#lzhou__lordwin"] = "江神全军陨落。",
  
  ["#lzhou_rule"] = "龙舟激浪",
  ["@&lzboss"] = "龙舟BOSS",
  ["@lzhou__zd"] = "争渡",
  ["@[:]lzhou__tianqi"] = "天气",
  ["@ganlu"] = "甘露",

  ["@@deng_god"] = "登神",
  

  ["@lz_draw"] = "摸牌",
    ["@lz_damage"] = "伤害",
    ["@lz_cover"] = "回复",
    ["@lz_control"] = "控制",
    ["@lzjd"] = "龙舟进度",
  [":lzhou_mode"] = desc_lzhou,
}

return lzhou_mode
